import { BaseService } from './BaseService';
import { API_ENDPOINTS } from './apiConfig';
import { User } from '../types';

// 登录凭据接口
interface LoginCredentials {
  phone: string;
  password: string;
}

// 注册凭据接口
interface RegisterCredentials {
  phone: string;
  code: string;
}

// 登录响应接口
interface LoginResponse {
  token: string;
  user: User;
}

// 用户服务类
export class UserService extends BaseService {
  // 用户登录
  async login(credentials: LoginCredentials): Promise<LoginResponse> {
    return this.post<LoginResponse>(API_ENDPOINTS.LOGIN, credentials);
  }

  // 用户登出
  async logout(): Promise<void> {
    return this.post<void>(API_ENDPOINTS.LOGOUT);
  }

  // 获取用户信息
  async getProfile(): Promise<User> {
    return this.get<User>(API_ENDPOINTS.GET_PROFILE);
  }

  // 更新用户信息
  async updateProfile(userData: Partial<User>): Promise<User> {
    return this.put<User>(API_ENDPOINTS.UPDATE_PROFILE, userData);
  }

  // 用户注册
  async register(credentials: RegisterCredentials): Promise<LoginResponse> {
    return this.post<LoginResponse>(API_ENDPOINTS.REGISTER, credentials);
  }
}

// 导出用户服务实例
export const userService = new UserService();
